package gameLogic;

import gameObject.Grasp;
import gameObject.Wife;

import ui.GamePanel;

public class GameThread extends Thread{
    GamePanel panle;
    Grasp grasp;
    Wife wife;
    Thread drawing;
    Thread moveing;
    public GameThread(GamePanel panle, Grasp grasp, Wife wife){
        this.panle = panle;
        this.grasp = grasp;
        this.wife = wife;
        //窗口重画的线程
        drawing = new Thread() {
            @Override
            public void run() {
                super.run();
                while (true) {
                    try {
                        Thread.sleep(30);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    panle.repaint(); //通过死循环让游戏画面不断刷新
                }
            }
        };
        //物体运动逻辑的线程
        moveing = new Thread(){
            @Override
            public void run() {
                super.run();
                while (true){
                    try {
                        Thread.sleep(30);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    grasp.move2();
                    wife.move();
                }
            }
        };
        //音乐播放的线程
    }
    //获取线程
    public Thread getDrawing() {
        return drawing;
    }

    public Thread getMoveing() {
        return moveing;
    }
}
